package com.adxon.data;

import com.adxon.MsgException;
import com.google.appengine.api.datastore.Entity;

public class Star extends Tagging{
	public final static String BSK="i6";

	private Item	tgt;	// target

	public Star(){
		bsk=BSK;
	}
	@Override
	protected String allocateId()throws MsgException{
		String r=ow+"/"+id;
		return tg==null?r:r+'/'+tg;
	}
	@Override
	public void commit()throws MsgException{
		if(ent==null){
			pk=allocateId();
			ent=new Entity(bsk,pk);
		}
		super.commit();
	}
	public Tagging getTarget(){
		if(tgt==null)
			if(id!=0) try{
				tgt=((Item)new Item().update(id)).extend();
			}catch(MsgException e){
				tgt=null;
			}else if(tg!=null) try{
				tgt=new Item();
				tgt.update("/tag/"+tg);
			}catch(MsgException e){
				tgt.tx=tg;
			}
		return tgt;
	}
}